Skip to content

Conversation

@marcschier
Copy link
Collaborator

@marcschier marcschier commented Jul 22, 2025

Added a string enumTypeName parameter to the ToEnumDefinition methods in ComplexTypeSystem.cs and DataTypeDefinitionExtension.cs to improve enum field name generation, especially when original names are null or empty. Implemented a fallback mechanism to ensure robust naming.

In ComplexTypeBuilder.cs, added null checks for typeName to prevent runtime errors and ensure valid type definitions. Updated logic for defining enum literals to handle empty field names, ensuring unique names are generated based on typeName and enum value.

Proposed changes

Describe the changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.

Related Issues

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply. You can also fill these out after creating the PR.

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

Added a `string enumTypeName` parameter to the `ToEnumDefinition` methods in `ComplexTypeSystem.cs` and `DataTypeDefinitionExtension.cs` to improve enum field name generation, especially when original names are null or empty. Implemented a fallback mechanism to ensure robust naming.

In `ComplexTypeBuilder.cs`, added null checks for `typeName` to prevent runtime errors and ensure valid type definitions. Updated logic for defining enum literals to handle empty field names, ensuring unique names are generated based on `typeName` and enum value.
@marcschier marcschier requested a review from Copilot July 22, 2025 19:11
@marcschier
Copy link
Collaborator Author

Fix for #3123

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

Attention: Patch coverage is 0% with 39 lines in your changes missing coverage. Please review.

Project coverage is 57.46%. Comparing base (bd6c91d) to head (3e117c4).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...Client.ComplexTypes/DataTypeDefinitionExtension.cs 0.00% 23 Missing ⚠️
...ent.ComplexTypes/TypeBuilder/ComplexTypeBuilder.cs 0.00% 13 Missing ⚠️
...es/Opc.Ua.Client.ComplexTypes/ComplexTypeSystem.cs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3124      +/-   ##
==========================================
+ Coverage   57.42%   57.46%   +0.04%     
==========================================
  Files         357      357              
  Lines       69117    69140      +23     
  Branches    14203    14216      +13     
==========================================
+ Hits        39687    39731      +44     
+ Misses      25180    25163      -17     
+ Partials     4250     4246       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marcschier marcschier marked this pull request as ready for review July 23, 2025 06:21
@marcschier marcschier self-assigned this Jul 23, 2025
Copy link
Contributor

@mrsuciu mrsuciu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a little glitch on calling EnumMemberAttribute

@marcschier marcschier requested a review from Copilot July 24, 2025 13:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances enum definition handling by adding robust validation and fallback mechanisms for enum field name generation. The changes address potential runtime errors when enum names are null or empty by implementing defensive coding practices and ensuring unique field names are generated.

  • Added enumTypeName parameter to ToEnumDefinition methods for improved fallback naming
  • Implemented null/empty validation for type names and enum fields with appropriate error handling
  • Enhanced enum literal definition logic to prevent duplicate field names and handle edge cases

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
ComplexTypeBuilder.cs Added null checks for typeName and enhanced enum field validation with duplicate prevention
DataTypeDefinitionExtension.cs Updated ToEnumDefinition methods to accept enumTypeName parameter and handle null/empty field names
ComplexTypeSystem.cs Updated method calls to pass enum type names to ToEnumDefinition methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Complex type builder fails with "Error: Failed to load the custom types."

4 participants